<?php
namespace app\common\helper;

use app\common\model\WxApiLog;

class weixin_helper
{
    /**
     * 修正要发送给微信的文本
     * @param string $content
     * @return string
     */
    public static function fix_weixin_content($content)
    {
        //$content = str_replace('<br>', "\n", $content);
        $content = html_entity_decode($content);

        $content = preg_replace('/\<br.*?\>/', "\n", $content);
        $content = strip_tags($content, '<a><img>');
        $content = str_replace('&nbsp;', '', $content);

        $content = emotion_helper::image_to_str($content);

        return $content;
    }

    /**
     * 添加微信api_log
     * @param array $info
     * @return int
     */
    public static function add_api_log($info)
    {
        if (!$info) {
            return 0;
        }

        return WxApiLog::create($info);
    }
}
?>
